package com.google.zxing.client.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

public class MenuActivity extends Activity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.main_menu);
		this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

		Button btnContinue = (Button) findViewById(R.id.btnContinue);
		btnContinue.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {

				Intent captureIntent = new Intent(MenuActivity.this, CaptureActivity.class);
				startActivity(captureIntent);
			}
		});

		Spinner spinner = (Spinner) findViewById(R.id.iterationsSpinner);
		ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.iterationsNumber, android.R.layout.simple_spinner_item);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinner.setAdapter(adapter);
		spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {

			public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
				switch (pos) {
				case 0:
					ThreadProperty.getInstance().setIterationNumber(1);
					break;
				case 1:
					ThreadProperty.getInstance().setIterationNumber(10);
					break;
				case 2:
					ThreadProperty.getInstance().setIterationNumber(20);
					break;
				case 3:
					ThreadProperty.getInstance().setIterationNumber(50);
					break;
				case 4:
					ThreadProperty.getInstance().setIterationNumber(100);
					break;
				case 5:
					ThreadProperty.getInstance().setIterationNumber(1000);
					break;
				}
			}

			public void onNothingSelected(AdapterView<?> parent) {
			}
		});

		Spinner spinnerThread = (Spinner) findViewById(R.id.spinner);
		ArrayAdapter<CharSequence> adapterThread = ArrayAdapter.createFromResource(this, R.array.threadNumber, android.R.layout.simple_spinner_item);
		adapterThread.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		spinnerThread.setAdapter(adapterThread);
		spinnerThread.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {

			public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
				switch (pos) {
				case 0:
					ThreadProperty.getInstance().setThreadNumber(1);
					break;
				case 1:
					ThreadProperty.getInstance().setThreadNumber(2);
					break;
				case 2:
					ThreadProperty.getInstance().setThreadNumber(3);
					break;
				case 3:
					ThreadProperty.getInstance().setThreadNumber(4);
					break;
				case 4:
					ThreadProperty.getInstance().setThreadNumber(5);
					break;
				}
			}

			public void onNothingSelected(AdapterView<?> parent) {
			}
		});

	}

}
